<?
function GetdichvuInfo($id,$status=0)
{
    global $con;
    $id=killInjection($id);
    if ($id=="") return false;
	$result = mysql_query("select * from dichvu where status=$status and news_id=$id  order by news_ordered desc limit 1",$con);
	return mysql_fetch_assoc($result);
}
function GetaboutInfo($id,$status=0)
{
    global $con;
    $id=killInjection($id);
    if ($id=="") return false;
	$result = mysql_query("select * from about where status=$status and news_id=$id  order by news_ordered desc limit 1",$con);
	return mysql_fetch_assoc($result);
}

function GetLinkAdv($row,$w,$h)
{
if (!isset($row)) return;

if ($w) $w="width=".$w;
if ($h) $h="height=".$h;

		$link=trim($row['link_websites_address']);
		$ext=GetFileExtention($row['link_websites_img']);
		switch ($ext)
		{
			case ".swf":
?>			
				<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj5" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" <? echo $w; ?> <? echo $h; ?>>
				<param name="movie" value="<? echo $link; ?>">
				<param name="quality" value="High">
				<embed src="'.$link.'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj5" <? echo $w; ?> <? echo $h; ?> quality="High"></object>
<?
				break;
			case ".gif":
			case ".jpg":
			case ".bmp":
			case ".png":
if ($link) 
{ if ($link!='#') {
?>
                        <a title="<? echo $row['link_websites_name']; ?> - <? echo $row['link_websites_address']; ?> (<? echo $row['link_websites_view']; ?>)" target="_blank" href="./?frame=adv&advid=<? echo $row['link_websites_id']; ?>&url=<? echo $row['link_websites_address']; ?>&go=1">
                        <img <? echo $w; ?> <? echo $h; ?> border="0" src="<? echo $row['link_websites_img']; ?>">
                        </a>
<? } else {
?>
                        <a title="<? echo $row['link_websites_name']; ?> - <? echo $row['link_websites_address']; ?> (<? echo $row['link_websites_view']; ?>)" href="#">
                        <img <? echo $w; ?> <? echo $h; ?> border="0" src="<? echo $row['link_websites_img']; ?>">
                        </a>
<?
	}                        
	} else { ?>
			<a title="<? echo $row['link_websites_name']; ?> (<? echo $row['link_websites_view']; ?>)" href="./?frame=adv&advid=<? echo $row['link_websites_id']; ?>">                        
			<img <? echo $w; ?> <? echo $h; ?> border="0" src="<? echo $row['link_websites_img']; ?>">
			</a>
<? } 
				break;		
			default:
				break; 
		}
}

function GetCategoryAllID($cat)
{
    global $con;
    $ret=$cat.",";
	$result = mysql_query("select * from categories where parent_id=$cat",$con);
	while (($row=mysql_fetch_assoc($result)))
	{
		$ret.=GetCategoryAllID($row['categories_id']);
	}
	return $ret;
}
function getinfo($table,$where="1=1")
{
	global $con;
    if ($table=="") return false;
    if ($where=="") $where="1=1";
	$result = mysql_query("select * from $table where $where",$con);
	return $result;
}

function CountRecord($table,$where="")
{
	global $con;
    if ($table=="") return false;
    if ($where=="") $where="1=1";
	$result = mysql_query("select count(*) as cnt from $table where $where",$con);
	$row=@mysql_fetch_assoc($result);
	return $row['cnt'];
}

//Count Page
function count_page($total, $n)
{
	if ($total%$n==0) return (int)($total/$n);
	return (int)($total/$n)+1;
}

//HAM NAY LOAI BO CAC LENH INJECTION
function killInjection($str){
	$bad = array("'","\\","=",":");
	$good = str_replace($bad,"", $str);
	return $good;
}

function GetCategoryInfo($catid)
{
    global $con;
    if ($catid=="") return false;
	$result = mysql_query("select * from categories where categories_id=$catid limit 1",$con);
	return @mysql_fetch_assoc($result);
}
function GetCategorydanhmuc($catid)
{
    global $con;
    if ($catid=="") return false;
	$result = mysql_query("select * from categories where parent_id=$catid limit 1",$con);
	return @mysql_fetch_assoc($result);
}
 
function GetProviderInfo($id)
{
    global $con;
    if ($id=="") return false;
	$result = mysql_query("select * from providers where providers_id=$id limit 1",$con);
	return @mysql_fetch_assoc($result);
}

function GetProductInfo($proid)
{
    global $con;
    if ($proid=="") return false;
	$result = mysql_query("select * from products where products_id=$proid limit 1",$con);
	return @mysql_fetch_assoc($result);
}

function GetListCategory($catid="",$split="==")
{
    global $con;
    $hide="categories_status=0";
    if (isset($_SESSION['log'])) $hide="1=1";
    $ret=array();
    if ($catid=="") $catid=0;
	$result = mysql_query("select * from categories where $hide and parent_id=$catid",$con);
	while (($row=mysql_fetch_assoc($result)))
	{
		$ret[]=array($row['categories_id'],($catid==0?"":$split).$row['categories_name']);
		$getsub=GetListCategory($row['categories_id'],$split.$split);
		foreach ($getsub as $sub)
			$ret[]=array($sub[0],$sub[1]);
	}
	return $ret;
}

function GetListProvider()
{
    global $con;
    $hide="providers_status=0";
    if (isset($_SESSION['log'])) $hide="1=1";
    $ret=array();
	$result = mysql_query("select * from providers where $hide order by providers_name",$con);
	while (($row=mysql_fetch_assoc($result)))
		$ret[]=array($row['providers_id'],$row['providers_name']);
	return $ret;
}

function GetConfig($name)
{
    global $con;
	$result = mysql_query("select * from config where config_name='$name'",$con);
	$row=mysql_fetch_assoc($result);
	return $row['config_value'];
}

function SetConfig($name,$value)
{
    global $con;
    $result = mysql_query("update config set config_value='".$value."' where config_name='$name'",$con);
    return $value;
}

function islogin()
{
if (isset($_SESSION['user']) && $_SESSION['user']!='') return $_SESSION['user'];
return false;
}

function price_in_cart()
{
	if (!isset($_SESSION['cart'])) return 0;
	global $con;
	$cart=$_SESSION['cart'];
	$tongcong=0;
	foreach ($cart as $product){
		$sql = "select * from products where products_id='".$product[0]."'";
		$result = mysql_query($sql,$con);
		if (mysql_num_rows($result)>0)
		{
			$pro=mysql_fetch_assoc($result);
			$tongcong=$tongcong+$pro['products_price']*$product[1];
			$cnt=$cnt+1;
		} 
	}
	return $tongcong;
}

function GetContent($id)
{
    global $con;
    if ($id=='') return false;
	$result = mysql_query("select * from contents where contents_id=$id limit 1",$con);
	$row=mysql_fetch_assoc($result);
	return $row['contents_content'];
}

function GetContentInfo($id)
{
    global $con;
    if ($id=='') return false;
	$result = mysql_query("select * from contents where contents_id=$id limit 1",$con);
	$row=mysql_fetch_assoc($result);
	return $row;
}

function GetContentName($name)
{
    global $con;
    if ($name=='') return false;
	$result = mysql_query("select * from contents where contents_name='".$name."' limit 1",$con);
	$row=mysql_fetch_assoc($result);
	return $row['contents_content'];
}

function GetContentNameInfo($name)
{
    global $con;
    if ($name=='') return false;
	$result = mysql_query("select * from contents where contents_name='".$name."' limit 1",$con);
	$row=mysql_fetch_assoc($result);
	return $row;
}

function GetListContent()
{
    global $con;
    $ret=array();
	$result = mysql_query("select * from contents",$con);
	while (($row=mysql_fetch_assoc($result)))
	{
		$ret[]=array($row['contents_id'],$row['contents_note']);
	}
	return $ret;
}

function GetListlinkcategoryweb()
{
    global $con;
    $hide="link_websites_categories_status=0";
    if (isset($_SESSION['log'])) $hide="1=1";
    $ret=array();
	$result = mysql_query("select * from link_websites_categories where $hide order by link_websites_categories_name",$con);
	while (($row=mysql_fetch_assoc($result)))
		$ret[]=array($row['link_websites_categories_id'],$row['link_websites_categories_name']);
	return $ret;
}
function GetListlinkweb($catid="",$split="==")
{
    global $con;
    $hide="link_websites_categories_status=0";
    if (isset($_SESSION['log'])) $hide="1=1";
    $ret=array();
    if ($catid=="") $catid=0;
	$result = mysql_query("select * from link_websites_categories where $hide and link_websites_categories_parentid=$catid",$con);
	while (($row=mysql_fetch_assoc($result)))
	{
		$ret[]=array($row['link_websites_categories_id'],($catid==0?"":$split).$row['link_websites_categories_name']);
		$getsub=GetListlinkweb($row['link_websites_categories_id'],$split.$split);
		foreach ($getsub as $sub)
			$ret[]=array($sub[0],$sub[1]);
	}
	return $ret;
}
function GetlinkInfo($catid)
{
    global $con;
    if ($catid=="") return false;
	$result = mysql_query("select * from link_websites_categories where link_websites_categories_id=$catid limit 1",$con);
	return @mysql_fetch_assoc($result);
}

function GetListCustomersVIP()
{
    global $con;   
    if (isset($_SESSION['log'])) $hide="1=1";
    $ret=array();
	$sql="select * from customers_vip where $hide order by customers_name";
	$result = mysql_query($sql,$con);
	while (($row=@mysql_fetch_assoc($result)))
		$ret[]=array($row['customers_id'],$row['customers_name'],$row['customers_company'],$row['customers_address'],$row['customers_phone'],$row['customers_email'],$row['customers_website'],$row['customers_image']);
	return $ret;
}
function GetCustomersInfo($catid)
{
    global $con;
    if ($catid=="") return false;
	$result = mysql_query("select * from customers where customers_id=$catid limit 1",$con);
	return @mysql_fetch_assoc($result);
}
/*function GetListCustomersVIP()
{
   global $con;     
    $ret=array();
	$sql="select * from customers_vip order by customers_id";
	$result = mysql_query($sql,$con);
	while (($row=mysql_fetch_assoc($result)))
		$ret[]=array($row['customers_vip_id'],$row['customers_id']);
	return $ret;
}*/

function GetListDonVi($id='')
{
    global $con;
    $ret=array();
	if($id=='') $id=0;
	$result = mysql_query("select * from donvi where parent_id=$id order by dv_id",$con);
	while (($row=mysql_fetch_assoc($result)))
	{
		$ret[]=array($row['dv_id'],$row['dv_name']);
	}
	return $ret;
}
function GetDonViInfo($id)
{
    global $con;
    if ($id=="") return false;
	$result = mysql_query("select * from donvi where dv_id=$id limit 1",$con);
	return @mysql_fetch_assoc($result);
}
?>